package database;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * Created with IntelliJ IDEA.
 * User: Wrflohil
 * Date: 28-5-13
 * Time: 13:58
 * SINGLETON
 */
public class DatabaseConnector {
    private static Connection connection;

    private static final String jdbc_driver = "com.mysql.jdbc.Driver";
    private static final String url = "jdbc:mysql://db4free.net:3306/d2dm";
    private static final String user = "d2dm";
    private static final String passw =  "amazons";

    private static DatabaseConnector instance = null;
    protected DatabaseConnector() {
        //
    }
    public static DatabaseConnector getInstance() {
        if(instance == null) {
            instance = new DatabaseConnector();
            try {
                Class.forName(jdbc_driver).newInstance();
                System.out.println("Driver instance made <<" +jdbc_driver+ ">>, trying connection.. to " +url);
                connection = DriverManager.getConnection(url, user, passw);
                System.out.println("Connected to the database");

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return instance;
    }

    public Connection getConnection() {
        return connection;
    }

}
